/**
 * Definition for singly-linked list.
 * class ListNode {
 *     val: number
 *     next: ListNode | null
 *     constructor(val?: number, next?: ListNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.next = (next===undefined ? null : next)
 *     }
 * }
 */

export class ListNode {
    val: number
    next: ListNode | null
    constructor(val?: number, next?: ListNode | null) {
        this.val = (val === undefined ? 0 : val)
        this.next = (next === undefined ? null : next)
    }
}
// 快慢指针
function middleNode(head: ListNode | null): ListNode | null {
    if(!head) return null
    let fast = head;
    let slow = head
    while (fast?.next && fast) {
        slow = slow.next;
        fast = fast.next.next;
    }
    console.log(slow);
    return slow;
};

const node: ListNode = new ListNode(1, new ListNode(2, new ListNode(3, new ListNode(4, new ListNode(5)))))
// console.log(node)
middleNode(node)
